package day25;

public class Thread02 extends Thread {

    public static int num = 1;
    static int flag = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (Thread02.class) {
                if (!Thread.currentThread().getName().equals(flag+"")) {
                    this.yield();
                }
                else {
                    if (num <= 100) {
                        System.out.println(Thread.currentThread().getName()+":"+num);
                        num++;
                        flag = flag == 0 ? 1 : 0;
                    } else break;
                }
            }
        }
    }
}
